from app.models.BaseModel import BaseModel
from app.db import db
from flask_login import UserMixin
class SysUser(BaseModel, UserMixin):
    """SysUserModel"""
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    email = db.Column(db.String(50), nullable=True)
    phone = db.Column(db.String(50), nullable=False)
    password = db.Column(db.String(100), nullable=False)
    role = db.Column(db.String(50), nullable=True)
    avatar = db.Column(db.String(100), nullable=True)
    status = db.Column(db.Integer, nullable=True)

    def __init__(self, name, email, phone, password, role, avatar, status):
        self.name = name
        self.email = email
        self.phone = phone
        self.password = password
        self.role = role
        self.avatar = avatar
        self.status = status

    def __str__(self):
        return f"SysUserModel(id={self.id}, username={self.username}, password={self.password}, email={self.email}, role={self.role}, created_at={self.created_at}, updated_at={self.updated_at})"
    
    def __repr__(self):
        return self.__str__()
    
    def to_dict(self):

        
        return {
            'id': self.id,
            'name': self.name,
            'email': self.email,
            'phone': self.phone,
            'password': self.password,
            'role': self.role,
            'avatar': self.avatar,
            'status': self.status,
            "create_time": self.create_time.strftime('%Y-%m-%d %H:%M:%S') if self.create_time  else None,
            "update_time": self.update_time.strftime('%Y-%m-%d %H:%M:%S')  if self.update_time  else None,
            "delete_time": self.delete_time.strftime('%Y-%m-%d %H:%M:%S') if self.delete_time  else None
        }